package com.yzt.zhuju.widget.pickview;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;

import androidx.core.content.ContextCompat;

import com.yzt.zhuju.R;
import com.yzt.zhuju.widget.pickview.builder.TimePickerBuilder;
import com.yzt.zhuju.widget.pickview.listener.OnTimeSelectListener;

import java.util.Calendar;
import java.util.Date;

/**
 * author : bob
 * date   : 2022/12/2
 * desc   :
 */
public class TimePickerViewManager {

    private TimePickerView mTimePicmkerView;

    private Calendar mSelectCalendar = Calendar.getInstance();

    private static TimePickerViewManager mInstance;

    private static Context mContext;

    public static TimePickerViewManager getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new TimePickerViewManager();
        }
        mContext = context;
        return mInstance;
    }

    public TimePickerView getTimePickerView() {
        return mTimePicmkerView;
    }

    public void setSelectCalendar(Calendar selectDate) {
        mSelectCalendar = selectDate;
    }

    /**
     * 控制时间范围(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
     * 因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
     */
    public void initTimePickerView(Activity activity, Calendar startDate, Calendar endDate, OnCallBackDateTimeListener listener) {
        //时间选择器
        mTimePicmkerView = new TimePickerBuilder(activity, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                listener.callBackDateTime(date);
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("", "", "", "时", "分", "秒")
                .setDividerColor(Color.DKGRAY)
                .setContentTextSize(20)
                .setLineSpacingMultiplier(2.0f)
                .setDate(mSelectCalendar)
                .setRangDate(startDate, endDate)
                .setOutSideCancelable(true)
                .setDividerColor(ContextCompat.getColor(mContext, R.color.color_bd2ffe))
                //设置选中项文字颜色
                .setTextColorCenter(ContextCompat.getColor(mContext, R.color.color_bd2ffe))
                .setLineSpacingMultiplier(2.0f)
                .setContentTextSize(15)
                .setTitleBgColor(ContextCompat.getColor(mContext, R.color.white))
                .setSubmitColor(ContextCompat.getColor(mContext, R.color.color_bd2ffe))
                .setCancelColor(ContextCompat.getColor(mContext, R.color.color_262628))
                .build();
    }

    public void showTimePicmkerView() {
        if (mTimePicmkerView != null) {
            mTimePicmkerView.show();
        }
    }

    public interface OnCallBackDateTimeListener {
        void callBackDateTime(Date date);
    }

}
